package com.lanp.springredis.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.Codec;
import org.redisson.codec.JsonCodecWrapper;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonConfig {

    @Value("${redis.database.category}")
    private int categoryDatabase;
    @Value("${redis.host}")
    private String host;
    @Value("${redis.port}")
    private int port;

    /**
     * 初始化redisson客户端
     * @return
     */
    @Bean
    public RedissonClient redissonClient() {
        Config sonConfig = new Config();
        Codec codec = new JsonJacksonCodec();
        sonConfig.useSingleServer()
                .setAddress("redis://" + host + ":" + port);
        sonConfig.setCodec(codec);
        return Redisson.create(sonConfig);
    }
}
